package microcredit.gui.table.impl;

import java.awt.Color;

import javax.swing.ImageIcon;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.gui.util.FormatUtilities;
import microcredit.model.MemberStatusHistory;
import microcredit.model.domain.Status;

enum MemberStatusHistoryColumn {
	STATUS,
	REASON,
	REASON_TEXT,
	DATE
}

public class MemberStatusHistoryTableModel extends
		EnumBeanTableModel<MemberStatusHistory, MemberStatusHistoryColumn> {

	@Override
	protected Object getValue(MemberStatusHistory o,
			MemberStatusHistoryColumn column) {
		switch (column) {
		case REASON:
			return o.getReason() != null ? o.getReason().toString() : " - ";
		case STATUS:
			return o.getStatus().toString();
		case REASON_TEXT:
			return o.getReasonText();
		case DATE :
			return FormatUtilities.formatDateTime(o.getInsertStamp());
		}
		return null;
	}
	
	@Override
	protected int getWidth(MemberStatusHistoryColumn column) {
		switch (column) {
		case REASON:
			return 200;
		case STATUS:
			return 70;
		case REASON_TEXT:
			return 300;
		case DATE :
			return 200;
		}
		return -1;
	}
	
	@Override
	protected Color getForeground(MemberStatusHistory o,
			MemberStatusHistoryColumn column) {
		if (o.getStatus() == Status.I) {
			return Color.RED;
		}
		return super.getForeground(o, column);
	}
	
	@Override
	public ImageIcon getRowIcon() {
		return new ImageIcon(MemberStatusHistory.class
				.getResource("/microcredit/icons/x16/id_card_edit.png"));
	}
	
	@Override
	protected Color getBackground(MemberStatusHistory o,
			MemberStatusHistoryColumn column) {
			return null;
	}
	
	@Override
	protected String getName(MemberStatusHistoryColumn column) {
		switch (column) {
		case REASON:
			return "Reason";
		case STATUS:
			return "Status";
		case REASON_TEXT :
			return "Text";
		case DATE :
			return "Date";
		}
		return null;
	}

}